package org.suyafei.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.suyafei.interceptor.LoginInterceptor;
import org.suyafei.manager.DomainManager;
import org.suyafei.model.DomainDO;
import org.suyafei.service.DomainService;
import org.suyafei.vo.DomainVO;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author 宿某人
 * @Date: 2022/01/07/5:50 下午
 * @Description:
 */
@Slf4j
@Service
public class DomainServiceImpl implements DomainService {
    @Autowired
    private DomainManager domainManager;

    @Override
    public List<DomainVO> listAll() {
        Long accountNo = LoginInterceptor.threadLocal.get().getAccountNo();
        List<DomainDO> customDomainDOList = domainManager.listCustomDomain(accountNo);
        List<DomainDO> officialDomainList = domainManager.listOfficialDomain();
        customDomainDOList.addAll(officialDomainList);
        return customDomainDOList.stream().map(obj->beanProcess(obj)).collect(Collectors.toList());
    }

    private DomainVO beanProcess(DomainDO domainDO) {
        DomainVO domainVO = new DomainVO();
        BeanUtils.copyProperties(domainDO, domainVO);
        return domainVO;
    }
}
